﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using DddCms.Domain.Model;
using DddCms.Domain.Utility;
using Microsoft.Practices.Unity;
using DddCms.Infrastructure.Logging;

namespace DddCms.Infrastructure.Repository
{
    /// <summary>
    /// Initialize database
    /// </summary>
    public class DatabaseInitializer : CreateDatabaseIfNotExists<DataContext>
    {
        [Dependency]
        public ILoggingUtil LoggingUtil { get; set; }
        /// <summary>
        /// Initialise chaque repository
        /// </summary>
        /// <param name="database"></param>
        protected override void Seed(DataContext database)
        {
            LoggingUtil.Information("Database", "Initializer", "Initialisation de la base de donné.");

            database.User.Add(new User()
            {
                UserName = "admin",
                Password = database.PasswordUtil.encryption("admin"),
                Roles = new List<Role>() { new Role() { Name = "admin" }, new Role() { Name = "user" } }
            });
            database.Save();
        }
    }
}
